package com.sgl.gk.tools;

import com.sgl.common.core.domain.AjaxResult;
import com.sgl.common.utils.StringUtils;
import com.sgl.gk.controller.vo.GkStationConfigurationVo;
import com.sgl.gk.domain.GkStation;
import com.sgl.gk.domain.GkStationConfiguration;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author:xec
 * @date:2022/12/28 16:27
 **/
public class BarCodeTool {

    public static String msg = null;

    /**
     * 返回值为true则验证通过，返回值为false则验证不通过
     * @param gkStationConfigurations
     * @return
     */
    public static Boolean inspect(List<GkStationConfiguration> gkStationConfigurations, List<GkStation> stations){
        Map<Long, List<GkStationConfiguration>> collect1 = gkStationConfigurations.parallelStream().collect(Collectors.groupingBy(GkStationConfiguration::getStationId));
        String prefix = "barcode";
        String suffix = "en";
        String suffix1 = "format";
        for (Long aLong : collect1.keySet()) {
            String stationName = new String();
            for (GkStation station : stations) {
                if (station.getId().longValue()==aLong.longValue()){
                    stationName = station.getName();
                }
            }
            List<GkStationConfiguration> gkStationConfigurationList = collect1.get(aLong);
            for (int i = 0; i < 5; i++) {
                String configName = prefix+(i+1)+suffix;
                for (GkStationConfiguration gkStationConfiguration : gkStationConfigurationList) {
                    if (gkStationConfiguration.getVariableName().equals(configName)){
                        if (gkStationConfiguration.getSaveValue().equals("true")){
                            String configName2 = prefix+(i+1)+suffix1;
                            for (GkStationConfiguration stationConfiguration : gkStationConfigurationList) {
                                if (stationConfiguration.getVariableName().equals(configName2)){
                                    if (StringUtils.isEmpty(stationConfiguration.getSaveValue())) {
                                        msg =stationName+":"+ configName2+"不能为空";
                                        return Boolean.FALSE;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return Boolean.TRUE;
    }

}
